package com.yyf.blogapi.controller;


import com.yyf.blogapi.common.cache.Cache;
import com.yyf.blogapi.common.log.LogAnnotation;
import com.yyf.blogapi.po.Article;
import com.yyf.blogapi.service.IArticleService;
import com.yyf.blogapi.vo.ArticleVo;
import com.yyf.blogapi.vo.PageParams;
import com.yyf.blogapi.vo.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author yyf
 * @since 2021-08-16
 */
@RestController
@RequestMapping("/articles")
public class ArticleController {

    @Resource
    IArticleService articleService;

//    @Cache(expire = 60*60*1000 , name = "文章列表")
    @LogAnnotation(module = "文章",operation = "列表")
    @PostMapping
    public Result listArticle(@RequestBody PageParams pageParams){
        return Result.success(articleService.listArticle(pageParams));
    }

//    @LogAnnotation(module = "文章",operation = "最热")
    @PostMapping("/hot")
    public Result hotArticle(){
        int limit = 5;
        return Result.success(articleService.hotArticle(limit));
    }

//    @LogAnnotation(module = "文章",operation = "最新")
    @PostMapping("/new")
    public Result newArticle(){
        int limit = 5;
        return Result.success(articleService.newArticle(limit));
    }

//    @LogAnnotation(module = "文章",operation = "归档")
    @PostMapping("/listArchives")
    public Result listArchives(){
        return Result.success(articleService.listArchives());
    }

    @LogAnnotation(module = "文章",operation = "详情")
    @PostMapping("/view/{id}")
    public Result viewArticle(@PathVariable("id") Long id){
        return Result.success(articleService.getArticleById(id));
    }

    @LogAnnotation(module = "文章",operation = "发布")
    @PostMapping("/publish")
    public Result publish(@RequestBody ArticleVo articleVo){
        return Result.success(articleService.publish(articleVo));
    }

}
